import 'package:common_utils/common_utils.dart';
import 'package:fate_blind_box/chat_pages/home/binding.dart';
import 'package:fate_blind_box/chat_pages/person_home/binding.dart';
import 'package:fate_blind_box/routes/page_route_names.dart';
import 'package:get/get.dart';

import 'chat_pages/home/logic.dart';
import 'network/http_config.dart';

class LoginMiddlewares extends GetMiddleware{
  @override
  Future<GetNavConfig?> redirectDelegate(GetNavConfig route) {
    // TODO: implement redirectDelegate
    print('LoginMiddlewares -- > redirectDelegate');
    return super.redirectDelegate(route);
  }

  @override
  GetPage? onPageCalled(GetPage? page) {
    // TODO: implement onPageCalled
    if(ObjectUtil.isNotEmpty( HttpConfig.token)){
      print('asd======');
    }else{
      print('登录失败？或者失效');
      if(Get.currentRoute != PageRouteNames.loginPage){
        Get.offAllNamed(PageRouteNames.loginPage);
      }
    }
    return super.onPageCalled(page);
  }

  @override
  List<Bindings>? onBindingsStart(List<Bindings>? bindings) {
    // TODO: implement onBindingsStart
    print('LoginMiddlewares -- > onBindingsStart');
    Get.lazyPut(()=>HomeLogic());
    HomeBinding().dependencies();
    PersonHomeBinding().dependencies();
    return super.onBindingsStart(bindings);
  }

  @override
  GetPageBuilder? onPageBuildStart(GetPageBuilder? page) {
    // TODO: implement onPageBuildStart
    print('LoginMiddlewares -- > onPageBuildStart');
    return super.onPageBuildStart(page);
  }

  @override
  void onPageDispose() {
    // TODO: implement onPageDispose
    print('LoginMiddlewares -- > onPageDispose');
    super.onPageDispose();
  }

}